package cn.tpshion.redismq.controller;

import cn.dev33.satoken.stp.StpUtil;
import cn.tpshion.redismq.data.UserMsg;
import cn.tpshion.redismq.handler.MessageProducer;
import com.alibaba.fastjson.JSON;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class TestController {

    @Resource
    private MessageProducer messageProducer;

    @GetMapping("/test")
    public String test() {
        log.info("send msg");
        String userId = StpUtil.getLoginIdAsString();
        UserMsg userMsg = new UserMsg();
        userMsg.setUserId(userId);
        userMsg.setMsg("hello world");
        messageProducer.sendMsg(JSON.toJSONString(userMsg));
        return "hello world";
    }
}
